package com.itheima.api.stream.demo01;

import java.util.*;
import java.util.stream.Stream;

public class StreamDemo01 {

    public static void main(String[] args) {

        // 针对Collection体系的集合直接调用Collection接口中所提供的stream方法进行流的获取
        Collection<String> col = new ArrayList<String>();
        col.add("hello");
        col.add("world");
        col.add("java");

        col.stream().filter(s -> s.length() > 4).forEach(s -> System.out.println(s));

        System.out.println("----------------------------------------------");

        //Map体系的集合间接的生成流(获取所有的键的集合，然后在生成流)
        Map<String, String> map = new TreeMap<String, String>();
        map.put("郭靖", "黄蓉");
        map.put("杨过", "小龙女");
        map.put("尔康", "紫薇");

        Set<String> keySet = map.keySet();

        keySet.stream().filter(s -> s.startsWith("杨")).forEach(s -> {
            String value = map.get(s);
            System.out.println(s + "----" + value);
        });

        System.out.println("-----------------------------------------------");

        //数组可以通过Stream接口的静态方法of(T... values)生成流
        Stream.of(25, 33, 45, 69, 78, 99).filter(s -> s > 50).forEach(s -> System.out.println(s));

    }

}
